#include <stdio.h>
#include <string.h>

char s1[102][35];
char s2[102][35];

int n1,n2;

int cc[105][105];
int site[105][105];

int isstr(char *in)
{
	int i, len;
	len=strlen(in);
	if (in[0]=='#' && len==1) return 1;
	for (i=0;i<len;i++)
		if (in[i]<'a' || in[i]>'z' ) return 0;
	return 1;
}

void count()
{
	int i,j;
	memset(cc,0,sizeof(cc));
	memset(site,0,sizeof(site));
	for (i=n1; i>=1; i--)
		for (j=n2; j>=1; j--)
		{
			if (strcmp(s1[i],s2[j])==0) 
			{
				cc[i][j]=cc[i+1][j+1]+1;
				site[i][j]=1;
			}
			else
			{
				cc[i][j]=cc[i+1][j] > cc[i][j+1] ? 
					(site[i][j]=2,cc[i+1][j]):(site[i][j]=3,cc[i][j+1]);
			}
		}
	
	i=j=1;
	int first=1;
	while (site[i][j]!=0)
	{
		if (site[i][j]==1)
		{
			if (first) printf("%s",(first=0,s1[i]));
			else printf(" %s", s1[i]);
			i++;j++;
		}
		else if (site[i][j]==2)
		{
			i++;
		}
		else if (site[i][j]==3)
		{
			j++;
		}
	}

}

main()
{
	char in[35];
	int now=0; // 0 for first ,1 for second

//	freopen("input","r",stdin);


	n1=0;
	n2=0;

	while (scanf("%s",in)!=EOF)
	{
		if (strlen(in)==0) continue;
		if (isstr(in)==0) continue;
		if (in[0]=='#')
		{
			now=now^1;
			if (now==0) 
			{
				count();
				
				printf("\n");
				n1=n2=0;

			}
			else
			{

			}
		}
		else
		{			
			if (now==0)	strcpy(s1[++n1],in);
			else        strcpy(s2[++n2],in);			 
			
		}
		


	} // end of while 

	return 0;
}

